<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="10">
          <el-form-item label="名称" prop="name" :rules="rules.validateRequire">
            <el-input v-model="model.name" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="" prop="name" label-width="5px">
            <el-button type="text" icon="el-icon-connection" @click="openRefFile">关联文件</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="文件最新版本号" prop="version" :rules="rules.validateRequire">
            <el-input v-model="model.version" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="流程id" prop="dispflowid">
            <el-input v-model="model.dispflowid" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="流程节点id" prop="dispnodeid">
            <el-input v-model="model.dispnodeid" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="文件地址类型" prop="urltype" :rules="rules.validateRequire">
            <el-select v-model="model.urltype" filterable clearable disabled>
              <el-option v-for="item in codeModel.urltypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="文件地址" prop="url" :rules="rules.validateRequire">
            <el-input v-model="model.url" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="操作类型" prop="operatetype" :rules="rules.validateRequire">
            <el-select v-model="model.operatetype" filterable clearable>
              <el-option v-for="item in codeModel.operatetypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="文件最后更新时间" prop="lastupdatetime">
            <el-date-picker v-model="model.lastupdatetime" type="datetime" placeholder="文件最后更新时间" value-format="yyyy-MM-dd HH:mm:ss" disabled></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="排序码" prop="sortcode" v-if="false">
            <el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效" prop="enabled" v-if="false">
            <el-radio-group v-model="model.enabled">
              <el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
    <ref-file-list ref="refFileList" @confirm="selectFile"></ref-file-list>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from "@tapui/mixins/mixin_edit"
/** 子组件 */
import refFileList from "./fileRefList"
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from "@tapui/utils/http"
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { refFileList },
  data() {
    return {
      moduleTitle: "流程文件",
      urlPrefix: "/base/flowFile/",
      url: {
        // 额外的url
      }
    }
  },
  props: {
    flowId: {
      default: "",
      type: String
    },
    nodeId: {
      default: "",
      type: String
    },
    dispNodeId: {
      default: "",
      type: String
    },
    dispFlowId: {
      default: "",
      type: String
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
      if (this.flowId) {
        this.$set(this.model, "flowid", this.flowId)
      }
      if (this.nodeId) {
        this.$set(this.model, "nodeid", this.nodeId)
      }
      if (this.dispNodeId) {
        this.$set(this.model, "dispnodeid", this.dispNodeId)
      }
      if (this.dispFlowId) {
        this.$set(this.model, "dispflowid", this.dispFlowId)
      }
    },
    openRefFile() {
      this.$refs.refFileList.visible = true
    },
    selectFile(selectedRows, selectedKeys, selectedValues) {
      this.$set(this.model, "name", selectedRows.name)
      this.$set(this.model, "version", selectedRows.version)
      this.$set(this.model, "lastupdatetime", selectedRows.modifiedon)
      this.$set(this.model, "url", selectedRows.groupid)
      this.$set(this.model, "urltype", "0")
    }
  }
}
</script>
